import csv
import json
import re
import numpy as np
import matplotlib.pyplot as plt

parsed_objects = []
sub_string_pattern = r"\d{1,2}[A-Z]{3}\d{4}\s\d{2}:\d{2}:\d{2}\.\d{3}"

path = 'data/3.normal aspirate sample/Sample aspirate/pressure data-6#/ued/200ul/Pressure_2024-02-18_10833_-1_-1.csv'

# 打开 CSV 文件
with open(path, newline='') as csvfile:
    # 创建一个 CSV 读取器对象
    csv_reader = csv.reader(csvfile)
    
    # 逐行读取 CSV 文件内容并打印出来
    for i, row in enumerate(csv_reader):
        if i == 5-1:  # 行号从0开始，所以是n-1
            result = ",".join(row)
            match = re.search(sub_string_pattern, result)
            start_index = match.start()
            end_index = match.end()
            modified_result = result[:start_index-1] + '0' + result[end_index+1:]
            fixed_json_str = re.sub(r'(?<!["\w])(\w+)(?=:)', r'"\1"', modified_result)
            jdata = json.loads(fixed_json_str)
            parsed_objects = jdata["Pressure_readings"]
            x = np.linspace(0, len(parsed_objects), len(parsed_objects))
            print(0)
            plt.plot(x,parsed_objects)
            plt.grid(True)
            plt.show()
